$(function(){
	//获取当前设备的设备像素比
	initPixelRatio()
	sharework();
	//$(".bannerbg").html('<img src="https://img.yzcdn.cn/upload_files/2017/10/26/FjvTxyHr7TWtQR9eJEcPYVIFg4re.jpg?imageView2/2/w/730/h/0/q/75/format/webp">')
	//旋转canvas中的图片    
		
})
var create_cvs = document.createElement('canvas');
var create_cvs_2d = create_cvs.getContext('2d');

var  shareid=GetRequest().work_id_str.split(',');
var shareworkid=new Array;
var delshareid=new Object; //未填充完整的作品

//把所有作品的图片转成对象
function sharework(){	
	for(var i=0;i< shareid.length; i++){
		 var w_id=shareid[i];		
		 shareworkid.push(w_id);
		 delshareid[w_id]=new Array;
		//获取已经存在的作品的作品页面信息
		baseAjax('other/work/work_page_list','GET',{work_id:w_id},function(data){
			
				if(UtilProperty[w_id]==null){
					UtilProperty[w_id]=new Object;
				}
				UtilProperty[w_id].worker=data.data;			
				UtilProperty[w_id].imageObj=new Object;
				if(UtilProperty[w_id].worker.length>0){
					var mulitImg=[];										
					var isfla=false;					
					for(var j=0; j<data.data.length;j++){
						var item=UtilProperty[w_id].worker[j];	
						var bgurl=item.background.image_url+bgsize_str;																
						if(item.background_id!=0){// lym 2018.01.02 修改 图片加载 原先的的id标志转为url标志	
							UtilProperty[w_id].worker[j].background.image_url=bgurl;	
							if(UtilProperty.background.backgroundimage[bgurl]==undefined){
								mulitImg.push(bgurl);
								UtilProperty.background.backgroundimage[bgurl]=null;
								isfla=true;
							}
						}
						
						for(k=0; k<item.control_list.length;k++){
							var element=item.control_list[k];			
							if(element.control_id==1){	
								if(element.element_list instanceof Array&&element.element_list.length>0){
									var list=element.element_list[0];
									if(list.image_url!=""){// lym 2018.01.02 修改 图片加载 原先的的id标志转为url标志
										var img_url=list.image_url+imgsize_str;
										UtilProperty[w_id].worker[j].control_list[k].element_list[0].image_url=img_url; 
										if($.inArray(img_url, mulitImg)==-1){
											mulitImg.push(img_url);										
											isfla=true;
										}
									}
								}
							
							}else if(element.control_id==2){				
								
							}else if(element.control_id==3){//lym 2017 11.17 新增月历修改
								if(element.element_list instanceof Array&&element.element_list.length>0){
									if(element.element_list[0].content==''||!element.element_list[0].content){
										/*delshareid[w_id].push(item.page);
										break;	*/
									}else{										
										var dateList=element.element_list[0];								
										if(dateList.style!=""&&dateList.style!=undefined){
											var a=JSON.parse(dateList.style);
											var fontstyle={align:a.align,color:a.color,direction:a.direction,line_space:a.line_space,max:a.max,size:a.size,format:a.format};
											dataObj.year=dateList.content.split('-')[0];
											dataObj.month=dateList.content.split('-')[1];
											element.element_list[0].date_list=calendarMonthdata(dataObj.year,dataObj.month,a.column,a.weekstyle,element.width,element.height,fontstyle);
											
										}
									}
								}
							}
						}
					}
					if(isfla){						
						//判断图片是否完全加载完毕
						imagelistToObject(mulitImg,w_id,function(){
							//判断是否所有作品的图片都加载完毕
 							judeEndwork();						
						})
					}else{
						//判断是否所有作品的图片都加载完毕
 						judeEndwork();
 						return false;
					}
					
				}else{
					shareworkid.splice(i,1);
					judeEndwork();
					return false;
						
				}
				
			})	
		break;	
	}
	
	
	
}

//判断是否所有作品的图片都加载完毕
function judeEndwork(){
	shareid.splice(0,1);
 	if(shareid.length>0){
		sharework();
	}else{
		showsharework();
	}
	
 	
 }
//遍历所有分享的作品
function showsharework(){
	
	for(var q=0;q<shareworkid.length; q++){
		var w_id=shareworkid[q];
		if(delshareid[w_id].length==0){
			generate_picture(w_id,false,-1,true,false);// lym 2018.01.02 修改 图片加载 原先的的id标志转为url标志	
		}else{
			for(var d=0; d<UtilProperty[w_id].worker.length;d++){
				/*if($.inArray(UtilProperty[w_id].worker[d].page, delshareid[w_id])>-1){
					var html='<div class="swiper-slide"><div class="swipetxt">当前简页已删除</div><div class="gallerytitle">'+UtilProperty[w_id].worker[d].title+'</div></div>';			
					$(".swiper-wrapper").append(html);
				}else{*/
					generate_picture(w_id,false,d,true,false);;// lym 2018.01.02 修改 图片加载 原先的的id标志转为url标志	
				//}					
				
			}
		}
		
		var arr= generate_imgurl[w_id].base64image;
		for(var j=0;j<arr.length;j++){			
			//var html='<div class="swiper-slide sharepicbg"><img src="'+arr[j].imgurl+'" style="background-image:url('+UtilProperty[w_id].worker[j].background.image_url+maxScreen.width/Pixel_Ratio+'x'+maxScreen.height/Pixel_Ratio+')"></div>';
			
			//var html='<div class="swiper-slide sharepicbg"><img src="'+arr[j].imgurl+'"></div>';
			var imgsty=UtilProperty[w_id].worker[0].width>UtilProperty[w_id].worker[0].height?"width:100%;":"height:100%;";
			var olditem=UtilProperty[w_id].worker[j];
			//var bg=olditem.background_id!=0?'background-image:url('+olditem.background.image_url+maxScreen.width/Pixel_Ratio+'x'+maxScreen.height/Pixel_Ratio+')':'';
			//var html='<div class="swiper-slide sharepicbg"><img src="'+arr[j].imgurl+'" style="'+imgsty+' background-image:url('+UtilProperty[w_id].worker[j].background.image_url+maxScreen.width/Pixel_Ratio+'x'+maxScreen.height/Pixel_Ratio+')"><div class="gallerytitle">'+arr[j].title+'</div></div>';
			var gallystr='';
			if(olditem.title=="封面"||olditem.title=="封底"||olditem.title=="扉页"){			
				gallystr=arr[j].title;
			}else{	
				gallystr='第'+olditem.page+'页';
			}
			
			var html='<div class="swiper-slide sharepicbg"><img src="'+arr[j].imgurl+'" style="'+imgsty+'"><div class="gallerytitle">'+gallystr+'</div></div>';
			$(".swiper-wrapper").append(html);
		}
	}
	
	$("#loadtoast").hide();	
	var swiper = new Swiper('.swiper-container', {
		followFinger : false        
    });
    if($(".swiper-slide").length==0){	
		$(".sharewrap").hide();
		$(".Emptywork").show();
		
	}
}



